package com.yowasa.xiuxian.engine.battle.strategy.drop.gold;

import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.CalAbility;
import com.yowasa.xiuxian.engine.battle.strategy.InherentStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.InherentTiming;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

@BS(name = "孤影亡身",upAbility = 4,needTravel = 1200)
@Order(-1000)
@Component
public class GuYingWangShen extends CalAbility implements InherentStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return ElementEnum.GOLD;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int i = first.getBattleInfo().getHp() / 20;
        first.getBattleInfo().setChp(first.getBattleInfo().getChp() - i);
        BuffContent buffContent = first.getBuff().get("孤影亡身");
        if (buffContent == null) {
            BuffContent buff = new BuffContent();
            buff.setDuration(5);
            buff.setNum(1);
            first.getBuff().put("孤影亡身", buff);
        }else{
            buffContent.setDuration(5);
            int num=buffContent.getNum() + 1;
            buffContent.setNum(num);
        }

    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("金") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用孤影亡身必须具有金灵根");
        }
        if (user.getStage() < StageEnum.ZHU_JI.getLevel()) {
            throw new HandlerException("学习/使用孤影亡身至少要始明之青");
        }
    }
    @Override
    public String limitDesc() {
        return "达到始明之青且具有金灵根";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        //校验蓝
        if (user.getBattleInfo().getHp()/user.getBattleInfo().getChp() >= 2) {
            return false;
        }
        return true;
    }

    @Override
    public List<InherentTiming> getTiming() {
        return Lists.newArrayList(InherentTiming.SELF_BEGIN);
    }

    @Override
    public String desc() {
        return "自己回合开始若血量大于50%，会燃烧5%的血量，为自己提升5%的攻击力\n当层数达到5层后，会清空该buff，造成1.0当前攻击力的免疫伤害，并回复本次伤害一半的hp";
    }
}
